package com.dinggao.bangda.view;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.dinggao.bangda.R;
import com.dinggao.bangda.initview.PassengerMain;
import com.dinggao.bangda.initview.PeopleMain;
import com.dinggao.bangda.interaction.CarownerFragment;
import com.dinggao.bangda.interaction.LogisticsFragment;

public class FragmentHome extends Fragment implements View.OnClickListener {

	private View view;
//	private PassengerFragment passenger_Fragment;
	private PassengerMain passengerMain;
	private PeopleMain peopleMain;
	private LogisticsFragment logistics_Fragment;
	private FragmentTransaction fragmentManager;
	private Button passenger_btn;
	private Button carowner_btn;
	private Button garowner_btn;
	private TextView siteTitle;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
							 Bundle savedInstanceState) {
		if (view == null) {
			view = inflater.inflate(R.layout.frag_home, null);
			return view;
		}
		return view;
	}

	@Override
	public void onActivityCreated(@Nullable Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		initView();
		fragmentManager = getChildFragmentManager().beginTransaction();
		fragmentManager.add(R.id.title_frag,passengerMain).commit();
	}
    public void initView(){
		passengerMain = new PassengerMain();
		peopleMain = new PeopleMain();
		logistics_Fragment = new LogisticsFragment();
		passenger_btn = (Button) view.findViewById(R.id.passenger_btn);
		passenger_btn.setOnClickListener(this);
		carowner_btn = (Button) view.findViewById(R.id.carowner_btn);
		carowner_btn.setOnClickListener(this);
		garowner_btn = (Button) view.findViewById(R.id.garowner_btn);
		garowner_btn.setOnClickListener(this);
		passenger_btn.setTextColor(getResources().getColor(R.color.menu_click));
		siteTitle = (TextView) view.findViewById(R.id.site_title);
		siteTitle.setOnClickListener(this);
	}
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.passenger_btn:
				fragmentManager = getChildFragmentManager().beginTransaction();
				fragmentManager.replace(R.id.title_frag,passengerMain).commit();

				passenger_btn.setTextColor(getResources().getColor(R.color.menu_click));
				carowner_btn.setTextColor(getResources().getColor(R.color.menu_text));
				garowner_btn.setTextColor(getResources().getColor(R.color.menu_text));
				break;
			case R.id.carowner_btn:
				fragmentManager = getChildFragmentManager().beginTransaction();
				fragmentManager.replace(R.id.title_frag,peopleMain).commit();

				passenger_btn.setTextColor(getResources().getColor(R.color.menu_text));
				carowner_btn.setTextColor(getResources().getColor(R.color.menu_click));
				garowner_btn.setTextColor(getResources().getColor(R.color.menu_text));
				break;
			case R.id.garowner_btn:
				fragmentManager = getChildFragmentManager().beginTransaction();
				fragmentManager.replace(R.id.title_frag,logistics_Fragment).commit();
				passenger_btn.setTextColor(getResources().getColor(R.color.menu_text));
				carowner_btn.setTextColor(getResources().getColor(R.color.menu_text));
				garowner_btn.setTextColor(getResources().getColor(R.color.menu_click));
				break;
			case R.id.site_title:
				Toast.makeText(getContext(), "FragmentHome", Toast.LENGTH_SHORT).show();
				break;
			default:
				break;
		}
	}
}
